@isTest
private class OppAboradControllerTest {
    static testMethod void testMethod1() {

    	Country__c coun = new Country__c();
    	coun.Country__c = '美国';
    	coun.Area1__c = '美洲(America)';
    	coun.Area2__c = '北美(North America)';
    	insert coun; 

    	IVDProductLineMarket__c ivdpline = new IVDProductLineMarket__c();
    	ivdpline.Country__c = coun.Id;
    	ivdpline.ProductLine__c = '生化';
    	insert ivdpline;




         Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerAbroad','Account');
       	acc.Country__c = coun.Id; 
        insert acc;


        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.PriceCompany__c = 'MKSY';
        p1.ProductName__c = '测试试剂';
        p1.NCCode__c = '000001';
        p1.Overseasproducts__c = true;
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p1;

        //新建
        PageReference page = new PageReference('/apex/OppAboard?id=' + acc.Id );
        System.Test.setCurrentPage(page);
        OppAboradController oppabc = new OppAboradController();
        oppabc.init();

         Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('ProductName__c','测试');
        oppabc.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap),'UTF-8');
        oppabc.search();
         Map<String,Object>saveMap = new Map<String,Object>();
        saveMap.put('intent',JSON.deserializeUntyped( EncodingUtil.urlDecode(oppabc.dataJson, 'UTF-8')));

        Map<String,String> accMap = new Map<String,String>();
       // accMap.put('FutureDevelopmentStrategy__c', '');
        accMap.put('Country__c', coun.Id);
        accMap.put('Address__c', '11');
        //accMap.put('PersonStructure__c', '');
       // accMap.put('TotalSalesAndProductPercent__c', '');
        //accMap.put('MainProductAndCooperationBrand_del__c', '');
       //accMap.put('Artificial__c', '');
        //accMap.put('Phone', '');
       // accMap.put('Fax', '123456');
        accMap.put('Email__c', '123test@maccura.com');
        accMap.put('AuthorityAreas__c', '');
        accMap.put('LastYearRevenue__c', '');
        //accMap.put('Website', '');
        Map<String ,Object> baseMap = new Map<String,Object>();
        baseMap.put('Account', accMap);
        Map<String,String> oppMap = new Map<String,String>();
      
        oppMap.put('ProjStartDate__c', '2019-01-01');
        oppMap.put('CloseDate', '2019-02-01');
        baseMap.put('Opportunity', oppMap);

        saveMap.put('base',baseMap);
        Map<String,String> cppriceMap = new Map<String,String>();
        cppriceMap.put('productLineId', ivdpline.Id );
        cppriceMap.put('product', '测试产品');
        saveMap.put('cpprice',new List<Object>{cppriceMap});
        oppabc.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap),'UTF-8');
        oppabc.save();
        System.debug('OppAboradControllerTest==>'+oppabc.msg);
        Opportunity opp = [select Id from Opportunity where AccountId=:acc.Id limit 1 ];
        
        opp.StageName = '市场沟通';
        update opp;
        opp.StageName = '合作细节谈判' ;
        update opp;
         PageReference page1 = new PageReference('/apex/OppAboard?id=' + opp.Id );
        System.Test.setCurrentPage(page1);
   		OppAboradController oppabc1 = new OppAboradController();
        oppabc1.init();



         PageReference page2 = new PageReference('/apex/OppAboard?id=' + opp.Id+'&drop=true' );
        System.Test.setCurrentPage(page2);
        OppAboradController oppabc2 = new OppAboradController();
        oppabc2.init();
                 //   Set<String>  fields = new Set<String>{'LostReason__c','Successfulcompany__c','Winningcompanychannel__c','LostReasoneDesc__c','SuccessfulModel__c','WhetherParticipate__c','ContractTime__c','SuccessfulBrand__c'};
        Map<String,String> oppMap1 = new Map<String,String>();
        Map<String,Object>saveMap1 = new Map<String,Object>();

        oppMap1.put('LostReason__c', '11');
        oppMap1.put('Successfulcompany__c', '11');
        Map<String ,Object> baseMap1 = new Map<String,Object>();
        baseMap1.put('Opportunity', oppMap1);

        saveMap1.put('base',baseMap1);
   
        oppabc2.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap1),'UTF-8');
        oppabc2.save();



    }
}